package com.chilly.other.jdk8.Interface;

import org.junit.Ignore;
import org.junit.Test;

/**
 * Java 8新特性之方法引用的基本使用
 * <p>
 * Created by Chilly Cui on 2021/1/6.
 */
public class MethodTest {

    public void printResult(String s, Printable printable) {
        printable.print(s);
    }

    //传统写法
    @Test
    @Ignore
    public void testPrintString() {
        printResult("hello lambda", new Printable() {
            @Override
            public void print(String s) {
                System.out.println(s);
            }
        });
    }

    //Lambda表达式写法
    @Test
    @Ignore
    public void testPrintStringWithLambda() {
        printResult("hello lambda", s1 -> System.out.println(s1));
    }

    //方法引用写法
    @Test
    public void testPrintStringWithReference() {
        printResult("hello lambda", System.out::println);
    }
}
